<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%--
  Created by IntelliJ IDEA.
  User: qupen
  Date: 2016/11/26
  Time: 14:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="../../include/head.jsp">
    <jsp:param name="title" value="维修信息录入"/>
</jsp:include>
<link rel='stylesheet' href='/css/flatpickr.min.css'/>
<jsp:include page="../../include/tenant_header.jsp"/>

<jsp:include page="../../include/tenant_sidebar.jsp"/>
<style>
    .change-width{
        width: 200px !important;
    }
</style>
<div class="content-wrapper">
    <section class="content-header">
        <h4 class="page-title"><spring:message code="label.tenant.add.faultRepair"/></h4>
    </section>
    <section class="content">
        <div class="box box-primary">
            <div class="box-body">
                <div class="form-horizontal">
                    <div class="sie-padding-top">
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.tenant.faultRepair.start.time"/>:</label>
                            <input id="deviceId" value="${deviceId}" class="hidden"/>
                            <input id="idleStartTime" value="${startTime}" class="hidden"/>
                            <input id="idleEndTime" value="${endTime}" class="hidden"/>
                            <div class="col-md-7">
                                <div class="sie-calendar-parent">
                                    <input type="text"  name='timepicker' class="form-control sie-calendar-input change-width" id="start_time">
                                    <img src="/images/calendar.png" class="sie-calendar-img"/>
                                </div>
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.tenant.faultRepair.end.time"/>:</label>
                            <div class="col-md-7">
                                <div class="sie-calendar-parent">
                                    <input type="text"  name='timepicker' class="form-control sie-calendar-input change-width" id="end_time">
                                    <img src="/images/calendar.png" class="sie-calendar-img"/>
                                </div>
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.tenant.fault.reason"/>:</label>

                            <div class="col-md-7">
                                <input id="faultReason" class="form-control sie-input-border sie-input-uwh"/>
                            </div>
                        </div>
                        <div class="form-group form-group-change">
                            <label class="col-md-5 sie-left-name"><spring:message code="label.tenant.repair.personnel"/>:</label>

                            <div class="col-md-7">
                                <input id="maintainUser" class="form-control sie-input-border sie-input-uwh"/>
                                <div style="margin-top: 79px;">
                                    <a id="create_button" class="solid-button-blue" href="javascript:;"
                                       style="margin-right: 30px;"><spring:message code="label.save"/></a>
                                    <a class="solid-button-orange" href="javascript:history.back(-1);"><spring:message code="label.cancel"/></a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <%--</div>--%>
    </section>
</div>
<jsp:include page="../../include/foot.jsp"/>
<script src="/js/flatpickr.min.js"></script>
<script>
    $(document).ready(function(){
        $('#start_time').flatpickr({
            enableTime: true,
            altInput: true,
            minDate:new Date($("#idleStartTime").val()),
            maxDate:new Date($("#idleEndTime").val()),
            altFormat: "Y-m-j H:i:S"
        });

        $('#end_time').flatpickr({
            enableTime: true,
            altInput: true,
            minDate:new Date($("#idleStartTime").val()),
            maxDate:new Date($("#idleEndTime").val()),
            altFormat: "Y-m-j H:i:S"
        });
        bindDateInputClickEvent();
        $("#create_button").click(function () {
            var data = JSON.stringify({
                deviceId:$("#deviceId").val(),
                idleStartTime:$("#idleStartTime").val(),
                startTime:$("#start_time").val()+":00",
                endTime:$("#end_time").val()+":00",
                faultReason:$("#faultReason").val(),
                maintainUser:$("#maintainUser").val()
            });
            $.ajax({
                type: "post",
                url: "/partner/{tenant}/api/v1/faultReason/update".replace("{tenant}",getKeyByUrl()),
                contentType: "application/json;charset=utf-8",
                data: data,
                success: function () {
                    swal({
                        title: '<spring:message code="label.add.success"/>',
                        text: "",
                        type: "success",
                        showCancelButton: false,
                        showConfirmButton: true,
                        confirmButtonText: '<spring:message code="label.admin.confirm"/> ',
                        animation: "slide-from-top"
                    }, function () {
                        window.location.replace("/partner/{tenant}/faultReason/list#fault".replace("{tenant}",getKeyByUrl()));
                    });
                },
                fail: function () {
                    swal("Error!", "", "error");
                }
            })
        })
    });
</script>
